<?php
 jimport('joomla.application.component.view');
 // Load the view framework
 if(!class_exists('VmView'))require(JPATH_COMPONENT_ADMINISTRATOR.DS.'helpers'.DS.'vmview.php');
 jimport('joomla.html.pane');
class svViewSunghiep extends JView
{
	function display()
	{
		$acid=JRequest::getVar('kaka');
		$task = JRequest::getCMD('task');
		switch ($task)
		{
			
			case 'add':
				$this->_edit($acid);
				break;
			case 'edit':
				$this->_edit($acid);
				break;
			default :
				$add_edit=JRequest::getVar('add_edit');
				if($add_edit=='')$this->_default();
				else $this->_edit();
				break;
		}
		parent::display();
	}
	function getList($selected)
	{
		$model=$this->getModel('sunghiep');
		// list can bo
		$option[]=array('key'=>0,'text'=>JText::_('Chọn cán bộ'));
		$array=$model->Listcanbo();
		$array=array_merge($option,$array);
		$this->array=$array;
		$attr='class="inputbox", onchange="submitform()"';
		$list['canbo']=JHTML::_('select.genericlist',$array,'sn_idcanbo',$attr,'key','text',$selected['canbo']);
		// list phong ban
		$option1[]=array('key'=>0,'text'=>JText::_('Chọn phòng ban'));
		$array1=$model->ListPhongban();
		$array1=array_merge($option1,$array1);
		$this->array=$array1;
		$attr='class="inputbox", onchange="submitform()"';
		$list['phongban']=JHTML::_('select.genericlist',$array1,'idphongban',$attr,'key','text',$selected['phongban']);
		// list don vi
		$option2[]=array('key'=>0,'text'=>JText::_('Chọn đơn vị'));
		$array2=$model->ListDonvi();
		$array2=array_merge($option2,$array2);
		$this->array=$array2;
		$attr='class="inputbox", onchange="submitform()"';
		$list['donvi']=JHTML::_('select.genericlist',$array2,'iddonvi',$attr,'key','text',$selected['donvi']);
		// list loai su nghiep
		$option3[]=array('key'=>0,'text'=>JText::_('Chọn su nghiep'));
		$array3=$model->ListLoaisunghiep();
		$array3=array_merge($option3,$array3);
		$this->array=$array3;
		$attr='class="inputbox"';
		$list['loaisunghiep']=JHTML::_('select.genericlist',$array3,'sn_idloaisunghiep',$attr,'key','text',$selected['idloaisunghiep']);
		$this->list=$list;
	}
	// hien thi chi tiet
	function _default()
	{
		jimport('joomla.html.pagination');
		$model=$this->getModel('sunghiep');
		// phan trang
		$total=$model->getTotal();
		$view=JRequest::getVar('view');
		global $mainframe;
		$param['limitstart']=$mainframe->getUserStateFromRequest('com_svquanlycanbo.'.$view.'.limitstart', 'limitstart',0,'int');
		$param['limit']=$mainframe->getUserStateFromRequest('com_svquanlycanbo.'.$view.'.limit', 'limit',$mainframe->getCfg('list_limit'),'int');
		$pager=new JPagination($total, $param['limitstart'], $param['limit']);
		// sap xep
		$param['order']=$mainframe->getUserStateFromRequest('com_svquanlycanbo.'.$view.'.order', 'filter_order','sn_id','cmd');
		$param['order_Dir']=$mainframe->getUserStateFromRequest('com_svquanlycanbo.'.$view.'.orderDir', 'filter_order_Dir','DESC','word');
		// get List
		$idcanbo=JRequest::getInt('sn_idcanbo');
		$donvi=JRequest::getInt('iddonvi');
		$phongban=JRequest::getInt('idphongban');
		$selected['canbo']=$idcanbo;
		$selected['donvi']=$donvi;
		$selected['phongban']=$phongban;
		$this->getList($selected);
		// fill du lieu
		$acid=JRequest::getVar('acid');
		$objectList=$model->getAllSunghiep($param,$acid);
		$this->assignRef('total', $total);
		$this->assignRef('acid', $acid);
		$this->assignRef('pager', $pager);
		$this->assignRef('param', $param);
		$this->assignRef('objectList', $objectList);
		//$this->_gridToolbar();
		//toolbar
		$this->toolbarDefault('Quản lý sự nghiệp cán bộ ');
	}
	function _edit($acid)
	{
		$idlist    = JRequest::getVar('cid',array(0),'','array');
		JArrayHelper::toInteger($idlist, array(0));
		$id     = $idlist[0];
		if($id==0)
		{
			$id=JRequest::getInt('id');
			if($id==0) $this->toolbarAdd('Cập nhật mới mốc sự nghiệp cán bộ');
			else 
			{
				$this->toolbarEdit('Chỉnh sửa mốc sự nghiệp cán bộ');
			}
		}
		else
		{
			$this->toolbarEdit('Chỉnh sửa mốc sự nghiệp cán bộ');
		}
		// lay du lieu tu model
		$model=$this->getModel('sunghiep');
		$object=$model->getSunghiepByID($id);
		// get list
		$idcanbo=JRequest::getInt('sn_idcanbo');
		if($idcanbo==0) $idcanbo=$object->sn_idcanbo;
		$donvi=JRequest::getInt('iddonvi');
		$phongban=JRequest::getInt('idphongban');
		$idloaisunghiep=$object->sn_idloaisunghiep;
		$selected['idloaisunghiep']=$idloaisunghiep;
		$selected['canbo']=$idcanbo;
		$selected['donvi']=$donvi;
		$selected['phongban']=$phongban;
		$this->getList($selected);
		
		// set layout
		$this->assignRef('id', $id);
		$this->assignRef('acid', $acid);
		$this->assignRef('object', $object);
		$this->setLayout('edit');
	}
	// them cac button tren thanh toolbar
	function toolbarDefault($title)
	{
		$acid=JRequest::getVar('acid');
		JToolBarHelper::title($title);
		if($acid==0)
		{JToolBarHelper::addNew();}
		JToolBarHelper::editListX();
		if($acid==0)
		{
			JToolBarHelper::deleteList();
		}
		
	}
	function toolbarAdd($title)
	{
		JRequest::setVar( 'hidemainmenu', 1 );
		JToolBarHelper::title($title);
		JToolBarHelper::save();
		JToolBarHelper::cancel();
	}
	function toolbarEdit($title)
	{
		JRequest::setVar( 'hidemainmenu', 1 );
		JToolBarHelper::title($title);
		JToolBarHelper::save();
		JToolBarHelper::apply();
		JToolBarHelper::cancel();
	}
	
}
?>